package com.huaguoguo.cyg.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huaguoguo.cyg.annotation.ResultModelBuilder;
import com.huaguoguo.cyg.entity.tl.dto.TlServerDTO;
import com.huaguoguo.cyg.entity.tl.qo.GangQO;
import com.huaguoguo.cyg.entity.tl.qo.PlayerQO;
import com.huaguoguo.cyg.entity.tl.vo.ServerInfoVO;
import com.huaguoguo.cyg.service.tl.data.ITlGangService;
import com.huaguoguo.cyg.service.tl.data.ITlPlayerService;
import com.huaguoguo.cyg.service.tl.data.ITlServerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 天龙排行榜前端控制器
 */
@Controller
@Slf4j
public class TLRankController {
    @Autowired
    private ITlServerService tlServerService;
    @Autowired
    private ITlGangService tlGangService;
    @Autowired
    private ITlPlayerService tlPlayerService;

    /**
     * 进入到帮派排行页面
     * @param model
     * @return
     */
    @GetMapping(value = "tlGangRank.html")
    public String gangRank(Model model){
        List<ServerInfoVO> serverInfoVOList = tlServerService.queryColumn("server_name");
        model.addAttribute("serverInfoVOList",serverInfoVOList);
        return "tlGangRank";
    }

    /**
     * 进入到玩家排行页面
     * @param model
     * @return
     */
    @GetMapping(value = "tlPlayerRank.html")
    public String playerRank(Model model){
        List<ServerInfoVO> serverInfoVOList = tlServerService.queryColumn("server_name");
        model.addAttribute("serverInfoVOList",serverInfoVOList);
        return "tlPlayerRank";
    }

    /**
     * 获取服务器下的小区列表
     * @param serverName
     * @param model
     * @return
     */
    @GetMapping("area/list")
    @ResultModelBuilder
    public Object getAreaList(String serverName,Model model){
        return tlServerService.getAreaList(serverName);
    }

    /**
     * 获取指定区和帮会的所有日期的列表，并按帮会名称分组
     * @param gangQOList
     * @return
     */
    @PostMapping("rank/gang")
    @ResultModelBuilder
    public Object getGangRank(@RequestBody List<GangQO> gangQOList){
        return tlGangService.getGangListByDate(gangQOList);
    }

    /**
     * 获取指定区和玩家的所有日期的列表，并按区：帮：玩家名 名称分组
     * @param playerQOList
     * @return
     */
    @PostMapping("rank/player")
    @ResultModelBuilder
    public Object getPlayerRank(@RequestBody List<PlayerQO> playerQOList){
        return tlPlayerService.getPlayerListByDate(playerQOList);
    }

    /**
     * 获取指定区当天的帮会列表
     * @param areaId
     * @return
     */
    @GetMapping("gang/cur/{areaId}")
    @ResultModelBuilder
    public Object getCurGangList(@PathVariable("areaId") Integer areaId){
        return tlGangService.getByAreaId(areaId);
    }

    /**
     * 获取指定区当天的玩家列表
     * @param areaId
     * @return
     */
    @GetMapping("player/cur/{areaId}")
    @ResultModelBuilder
    public Object getCurPlayerList(@PathVariable("areaId") Integer areaId){
        return tlPlayerService.getByAreaId(areaId);
    }

}
